﻿using jbt.CodeCandy.AsTrEAM.StreamManager;
using System;

namespace jbt.CodeCandy.AsTrEAM
{
    /// <summary>
    /// Creates <see cref="IStreamManager"/> objects.
    /// </summary>
    public static class StreamManagerFactory
    {
        private static Func<IStreamManager> _fileManagerFactory;

        static StreamManagerFactory()
        {
            _fileManagerFactory = () => new SqlServerFileStreamManager();
        }

        /// <summary>
        /// Creates a new <see cref="IStreamManager"/> object.
        /// </summary>
        /// <returns>
        /// A new <see cref="IStreamManager"/> object.
        /// </returns>
        public static IStreamManager Create()
        {
            var fileManager = _fileManagerFactory();

            return fileManager;
        }

        /// <summary>
        /// Overrides the default factory.
        /// </summary>
        /// <param name="fileManagerFactory">
        /// Creates <see cref="IStreamManager"/> objects.
        /// </param>
        public static void UseFactory(Func<IStreamManager> fileManagerFactory)
        {
            if (fileManagerFactory == null)
            {
                throw new ArgumentNullException("fileManagerFactory");
            }

            _fileManagerFactory = fileManagerFactory;
        }
    }
}